package v1

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"server/internal/model"
	"server/pkg/app"
)

func CreaeNode(c *gin.Context) {
	userinfo := GetUser(c)

	node := &model.Node{}
	_ = c.ShouldBind(node)
	node.OwnerID = userinfo.ID
	err := node.Create()
	if err != nil {
		c.String(http.StatusOK, err.Error())
		return
	}
	c.String(http.StatusOK, "创建成功")
}

func GetAllNodes(c *gin.Context) {
	pages := &app.Page{}
	pages.Info(c)
	node := &model.Node{}
	node_list, total := node.List(pages)
	c.JSON(http.StatusOK, gin.H{
		"total": total,
		"data":  node_list,
	})
}

func GetNodeCpuModel(c *gin.Context) {
	ip := c.Query("ip")
	node := &model.Node{MinNode: model.MinNode{IP: ip}}
	cpu_model := node.CpuModel()
	c.String(http.StatusOK, cpu_model)
}

func GetNodeKernalInfo(c *gin.Context) {
	ip := c.Query("ip")
	node := &model.Node{MinNode: model.MinNode{IP: ip}}
	cpu_model := node.KernalInfo()
	c.String(http.StatusOK, cpu_model)
}
